#  Gmof - A meta-object facility library based on OMG's EMOF 
#
#  Copyright (C) 2007 Peter Hagg <peter.hagg@iki.fi>
#
#  This library is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public
#  License as published by the Free Software Foundation; either
#  version 2.1 of the License, or (at your option) any later version.
#
#  This library is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with this library; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
import unittest
from gmof.Class import Class
from gmof.Property import Property
from gmof.String import String
from gmof.Operation import Operation
from gmof.Parameter import Parameter

class ClassTest(unittest.TestCase):
    
    def setUp(self):
        self.klass = Class("TestClass")
    
    def tearDown(self):
        del self.klass
        
    def testCreation(self):
        """Test that the Class object gets created an initialized correctly"""
        self.assertFalse(None, self.klass)
        
    def testProperty(self):
        """Test that a Property is added to a Class correctly"""
        str = String("String", "")
        attribute = Property("name", str)
        self.klass.ownedAttribute.append(attribute)
        attribute.klass = self.klass
        
        self.assertTrue("name", attribute.name)
        self.assertEquals(attribute.klass, self.klass)
        self.assertEquals(1, len(self.klass.ownedAttribute))
        
    def testOperation(self):
        """Test that an Operation is added to a Class correctly"""
        str = String("String", "")
        getName = Operation("getName", str)
        self.klass.ownedOperation.append(getName)
        getName.klass = self.klass
        
        self.assertEquals(str, getName.type)
        self.assertEquals(1, len(self.klass.ownedOperation))
        self.assertEquals("getName", getName.name)
    
    def testParameter(self):
        """Test that a Paramter is added to an Operation correctly"""
        str = String("String", "")
        setName = Operation("setName", None)
        self.klass.ownedOperation.append(setName)
        setName.klass = self.klass
        
        self.assertEquals(None, setName.type)
        self.assertEquals(1, len(self.klass.ownedOperation))
        self.assertEquals("setName", setName.name)
        
        name = Parameter("name", str)
        setName.ownedParameter.append(name)
        name.operation = name
        
        self.assertEquals(str, name.type)
        self.assertEquals(1, len(setName.ownedParameter))
        self.assertEquals("name", name.name)
        
